﻿from locust import HttpLocust, TaskSet


def login(i):
    i.client.post("/login", {"username": "ellen_key", "password":
        "education"})


def logout(i):
    i.client.post("/logout", {"username": "ellen_key", "password":
        "education"})


def index(i):
    i.client.get("/")


def profile(i):
    i.client.get("/profile")


class UserBehavior(TaskSet):  # 用户行为类
    def on_start(self):
        login(self)

    def on_stop(self):
        logout(self)

    tasks = {index: 2, profile: 1}  # 定义任务事件的请求比例


class WebsiteUser(HttpLocust):  # 蝗虫类
    task_set = UserBehavior
    min_wait = 3000
    max_wait = 6000

from locust import HttpLocust, TaskSet, task,HttpUser

headers = {'Content-Type': 'application/json;charset=utf-8'}
class ScriptTasks(TaskSet):
    def on_start(self):
        self.client.post("/api/user/general/login?account=18850369373&password=x5HMgFqOWTp/s0sSE3QagQ==&channel=W",headers=headers)

    # @task(1)
    # def index(self):
    #     self.client.get("/")
    #
    # @task(1)
    # def about(self):
    #     self.client.get("/about/")

    @task(1)
    def demo(self):
        #产品列表
        data={"filter":{"prdType":"N","saleStatus":"1"}}
        self.client.post("/api/query/products",data=data, headers=headers)

class WebsiteUser(HttpUser):
    task_set = ScriptTasks
    host = "https://new-stg.innisfree.cn"
    min_wait = 1000
    max_wait = 2000